//
//  GoodsManageViewModel.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/4/18.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "GoodsManageViewModel.h"
#import "GoodsManageModel.h"
@interface GoodsManageViewModel ()
@property (nonatomic ,strong) NSMutableArray *listViewModel;
@end

@implementation GoodsManageViewModel

-(NSMutableArray *)listViewModel {
    
    if (!_listViewModel) {
        self.listViewModel = [NSMutableArray array];
    }
    return _listViewModel;
}

- (void)loadGoodsListNetWorking:(NSString *)bh andReturnValue:(returnValueBlock)returnValue andReturenError:(returenErrorBlock)returenError {
    
//    http://118.190.98.64/tctxAPI/shop_admin_commodity.aspx?bh=数字
    NSString *urlStr = [NSString stringWithFormat:@"%@/shop_admin_commodity.aspx",serverUrl];
    NSDictionary *paramDic = @{@"bh":bh};
    [NetworkManager requestPOSTWithURLStr:urlStr paramDic:paramDic finish:^(id responseObject) {
        NSLog(@"请求成功%@",responseObject);
        if (RESPONSEOBJECT) {
            NSDictionary *returnDic = [NSDictionary dictionaryWithDictionary:responseObject];
            NSArray *dataArray = [returnDic objectForKey:@"data"];
            for (NSDictionary *dic in dataArray) {
                GoodsManageModel *model = [[GoodsManageModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                [self.listViewModel addObject:model];
                
            }
            
            returnValue(self.listViewModel);
        }else{
            
            CustomAlertActionView *alertView = [[CustomAlertActionView alloc] initWithViewType:(AlertTypeNotButton)];
            alertView.title = responseObject[@"message"];
            [alertView show];
        
        }

      
    } enError:^(NSError *error) {
        NSLog(@"请求失败%@",error);
        returenError(error);
    }];

}


@end
